package com.Main.faislamovers;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.MarshalBase64;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class FeedBack extends Activity  {
	
	////////// That class not in use //////////////
	
	
	String NAMESPACEFD="http://tempuri.org/";
	String METHODNAMEFB="Feedback";
	String urlF="http://10.0.2.2:49173/Service1.asmx?wsdl";
	String SopaActionFD="http://tempuri.org/Feedback";
	
	 CheckBox chkIos, chkAndroid, chkWindows;
	 Button btnDisplay;
	 EditText edt_name,edt_phn_number,edt_email_id,edt_comment;
	 String txt_edt_name, txt_edt_phn_number,txt_edt_email,txt_edt_comment;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feedback);
		//chkIos = (CheckBox) findViewById(R.id.check_bx_complaints);
		//chkAndroid = (CheckBox) findViewById(R.id.check_bx_complments);
		//chkWindows = (CheckBox) findViewById(R.id.check_bx_suggestions);
		
		edt_name=(EditText) findViewById(R.id.edt_txt_name);
		edt_phn_number = (EditText) findViewById(R.id.edt_phn_numb);
		edt_email_id = (EditText) findViewById(R.id.edt_txt_email);
		edt_comment = (EditText) findViewById(R.id.edt_txt_comment);

		addListenerOnButton();
		Spinner spinner = (Spinner) findViewById(R.id.spinner_feedback);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
        this, R.array.arry_feedback_type, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        
        chkIos.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (((CheckBox) arg0).isChecked()) {
					Toast.makeText(FeedBack.this,
				 	   "Bro, try Android :)", Toast.LENGTH_LONG).show();
				}
			}
		});
        
        
        chkAndroid.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (((CheckBox) v).isChecked()) {
					Toast.makeText(FeedBack.this,
				 	   "Bro, try Android :)", Toast.LENGTH_LONG).show();
				}
			}
		});
        
        chkWindows.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (((CheckBox) v).isChecked()) {
					Toast.makeText(FeedBack.this,
				 	   "Bro, try Android :)", Toast.LENGTH_LONG).show();
				}
			}
		});
	}
	
	
	public void addListenerOnButton() {

		btnDisplay = (Button) findViewById(R.id.btn_submit);
		
		btnDisplay.setOnClickListener(new OnClickListener() {
	 
	       //Run when button is clicked
		  @Override
		  public void onClick(View v) {
	 
			//StringBuffer result = new StringBuffer();
			//result.append("IPhone check : ").append(chkIos.isChecked());
			//result.append("\nAndroid check : ").append(chkAndroid.isChecked());
			//result.append("\nWindows Mobile check :").append(chkWindows.isChecked());
	 
			try
			{
			txt_edt_phn_number= edt_phn_number.getText().toString();
			txt_edt_name=edt_name.getText().toString();
			txt_edt_email=edt_email_id.getText().toString();
			txt_edt_comment=edt_comment.getText().toString();
			
			setcustMsisdnFB();
			
			//Toast.makeText(FeedBack.this, result.toString(),
			//		Toast.LENGTH_LONG).show();
			
			}
			catch(Exception e)
			{
				
			}
			

	 
		  }
		});
	 
	  }
			
	
	
	
	
	

	public boolean setcustMsisdnFB() throws IOException, XmlPullParserException {
		   
		   SoapObject request = new SoapObject(NAMESPACEFD, METHODNAMEFB);
		   request.addProperty("feedback_type","Complaint" );
		   request.addProperty("subject", "Mobile");
		   request.addProperty("comment", txt_edt_comment);
		   request.addProperty("name", txt_edt_name);
		   request.addProperty("email_id", txt_edt_email);
		   request.addProperty("phn_number", txt_edt_phn_number);
		   
		  
		   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		   envelope.dotNet = true;
		   MarshalBase64 m = new MarshalBase64();
		   m.register(envelope);
		   envelope.encodingStyle = SoapEnvelope.ENC;
		   // send request
		   envelope.setOutputSoapObject(request);
		   HttpTransportSE androidHttpTransport = new HttpTransportSE(urlF);
		   androidHttpTransport.call(SopaActionFD, envelope);
		   // get response
		   KvmSerializable ks = (KvmSerializable) envelope.bodyIn;
		   String result = ks.getProperty(0).toString();
		   
		   
		   if (result.equals("Successs")) {
			   Toast.makeText(FeedBack.this,
				 	   "SignUp Success", Toast.LENGTH_LONG).show();
		    return true;
		   } else {
			   Toast.makeText(FeedBack.this,
				 	   "Signup Failed", Toast.LENGTH_LONG).show();
		    return false;
		   }

		  }
	
	
}
